#include <bits/stdc++.h>

using namespace std;
const int INF=1000000010;
int main_1101_2()
{
    int N;
    scanf("%d",&N);
    int ans[N],num=0;
    int leftMax[N+1],rightMin[N+1],seq[N+1];
    seq[0]=leftMax[0]=0;
    for (int i=1; i<=N ; ++i )
    {
        scanf("%d",&seq[i]);
        leftMax[i]=max(leftMax[i-1],seq[i-1]);
    }
    rightMin[N]=INF;
    for (int i=N-1; i>0 ; --i )
    {
        rightMin[i]=min(rightMin[i+1],seq[i+1]);
    }
    for (int i=1; i<=N ; ++i )
    {
        if (seq[i]>leftMax[i]&&seq[i]<rightMin[i])
        {
            ans[num++]=seq[i];
        }
    }
    printf("%d\n",num);
    if (num!=0)
    {
        --num;
        for (int i=0;i<num ;++i )
        {
            printf("%d ",ans[i]);
        }
        printf("%d",ans[num]);
    }
    else
    {
        printf("\n");
    }
    return 0;
}
